import { AddressItemType } from '@/basePackage/pages/addressManage/types'
import { AFSSTATUS } from '@/basePackage/pages/applyAfterSales/types'

/**
 * @param: UNFINISHED  未处理完成
 * @param: ACCOMPLISH 已处理完成
 */
export enum NotifyStatus {
    UNFINISHED,
    ACCOMPLISH,
}

/**
 * @param: WITHOUT  无需物流发货
 * @param: EXPRESS 普通发货 自己填 物流公司与 单号
 * @param: PRINT_EXPRESS 打印发货
 */
export enum DeliverType {
    WITHOUT,
    EXPRESS,
    PRINT_EXPRESS,
}

/**
 * 订单状态
 * @param  UNPAID 未支付
 * @param  PAID 已支付
 * @param  BUYER_CLOSED 买家关闭订单
 * @param  SYSTEM_CLOSED 系统关闭订单
 * @param  SELLER_CLOSED 卖家关闭订单
 */
export enum ORDERSTATUS {
    UNPAID,
    PAID,
    BUYER_CLOSED,
    SYSTEM_CLOSED,
    SELLER_CLOSED,
    TEAMING,
    TEAM_FAIL,
}

/**
 * 订单tab状态
 * @param UNPAID 待支付
 * @param UN_DELIVERY 待发货
 * @param UN_RECEIVE 待收货
 * @param COMPLETED 已完成
 * @param CLOSED 已关闭
 * @param UN_COMMENT 待评价
 */
export enum QUERYORDERSTATUS {
    // UNPAID,
    UN_DELIVERY,
    UN_RECEIVE,
    COMPLETED,
    UN_COMMENT,
    CLOSED,
}

export enum SHOPITEMSTATUS {
    OK,
    CLOSED,
}

/**
 * 订单类型
 * @param COMMON 商品订单
 * @param SPIKE 秒杀
 */
enum ORDERTYPE {
    COMMON,
    SPIKE,
}

export enum ORDERPAYMENT {
    WECHAT,
    ALIPAY,
    BALANCE,
}

/**
 * 订单支付状态
 * @param CLOSED 取消支付
 * @param UNPAID 未支付
 * @param PAID 已支付
 */
enum ORDERPAYMENTSTATUS {
    CLOSED,
    UNPAID,
    PAID,
}

/**
 * 优惠类型
 * @param PLATFORM_COUPON 平台优惠券
 * @param SHOP_COUPON 店铺优惠券
 */
enum DISCOUNTSOURCETYPE {
    PLATFORM_COUPON,
    SHOP_COUPON,
    freightPrice,
    MEMBER_DEDUCTION,
    FULL_REDUCTION,
    CONSUMPTION_REBATE,
}

/**
 * 优惠状态
 */
enum DISCOUNTSOURCESTATUS {
    NORMAL,
    CLOSED,
}

/**
 * 商铺订单状态
 * @param SYSTEM_CLOSED 系统关闭
 * @param BUYER_CLOSED  买家关闭订单
 * @param SELLER_CLOSED  卖家关闭订单
 */
export enum SHOPORDERSTATUS {
    OK,
    SYSTEM_CLOSED,
    BUYER_CLOSED,
    SELLER_CLOSED,
}

/**
 * 包裹状态
 * @param  WAITING_FOR_DELIVER 待发货
 * @param WAITING_FOR_RECEIVE  待收货
 * @param BUYER_WAITING_FOR_COMMENT 买家确认收货 待评价
 * @param SYSTEM_WAITING_FOR_COMMENT 系统确认收货 待评价
 * @param BUYER_COMMENTED_COMPLETED 买家已评论 已完成
 * @param SYSTEM_COMMENTED_COMPLETED 系统自动好评 已完成
 */
export enum PACKAGESTATUS {
    WAITING_FOR_DELIVER,
    WAITING_FOR_RECEIVE,
    BUYER_WAITING_FOR_COMMENT,
    SYSTEM_WAITING_FOR_COMMENT,
    BUYER_COMMENTED_COMPLETED,
    SYSTEM_COMMENTED_COMPLETED,
}

/**
 * 包裹配置方式
 * @param EXPRESS 快递
 */
enum PACKAGETYPE {
    EXPRESS,
}

/**
 * 订单类型
 * @param {string} buyerId 买家用户id
 * @param {string} no 订单号
 * @param {ORDERSTATUS} status 订单状态
 * @param {ORDERTYPE} type 订单类型
 * @param {OrderPayment} orderPayment 订单支付相关信息
 * @param {OrderDiscount} orderDiscounts 订单优惠相关
 * @param {ShopOrder} shopOrders 店铺订单相关
 */
export interface ApiOrder {
    id: string
    shopId: string
    buyerId: string
    no: string
    createTime: string
    updateTime: string
    status: keyof typeof ORDERSTATUS
    type: keyof typeof ORDERTYPE
    remark: string
    timeout: KeyNodeTimeout
    orderPayment: OrderPayment
    orderDiscounts: OrderDiscount[]
    shopOrders: ShopOrder[]
    payTimeOut?: string
    orderReceiver: AddressItemType
    // shopOrderPackages?: ApiLogistics01[]
}

export interface KeyNodeTimeout {
    commentTimeout: string
    confirmTimeout: string
    payTimeout: string
    confirmTimeoutMills: string
    payTimeoutMills: string
    commentTimeoutMills: string
}

export type OrderInfo = ApiOrder & ShopOrder

/**
 * 支付相关信息
 * @param payerId 支付用户id
 * @param type 支付类型
 * @param status 支付状态
 * @param totalAmount 订单总金额
 * @param freightAmount 总运费
 * @param discountAmount 优惠总金额
 * @param payTime 支付时间
 * @param payAmount 支付总金额金额 = 订单总金额 - 优惠总金额
 */
export interface OrderPayment {
    id: string
    sn: string
    createTime: string
    shopId: string
    orderNo: string
    payerId: string
    type: keyof typeof ORDERPAYMENT
    totalAmount: string
    freightAmount: string
    discountAmount: string
    payAmount: string
    payTime: string
}

/**
 * 订单优惠
 * @param sourceType 优惠类型
 * @param sourceStatus 优惠状态
 * @param sourceId 优惠源Id
 * @param sourceAmount 优惠金额
 * @param sourceDesc 优惠信息描述
 * @param discountItems 优惠项对应商品
 */
export interface OrderDiscount {
    shopId: string
    orderNo: string
    sourceType: keyof typeof DISCOUNTSOURCETYPE
    sourceStatus: keyof typeof DISCOUNTSOURCESTATUS
    sourceId: string
    sourceAmount: number
    sourceDesc: string
    discountItems: OrderDiscountItem[]
}

/**
 * 优惠对应的商品
 * @param packageId 店铺包裹id
 * @param packageItemId 店铺包裹商品id
 * @param discountId 优惠项id
 */
interface OrderDiscountItem {
    shopId: string
    packageId: string
    packageItemId: string
    discountId: string
    discountAmount: string
}

/**
 * 店铺订单相关
 * @param no 店铺订单号
 * @param remark 店铺订单备注
 */
export interface ShopOrder {
    no: string
    status: keyof typeof SHOPORDERSTATUS
    shopId: string
    orderNo: string
    shopName: string
    shopLogo: string
    remark: string
    shopOrderItems: ShopOrderItem[]
    createTime: string
    orderReceiver?: AddressItemType
    updateTime?: string
    id: string
    isCheck: boolean
}

export interface ShopOrderItem {
    afsNo?: string
    afsStatus: keyof typeof AFSSTATUS
    dealPrice: string
    fixPrice: string
    status: keyof typeof SHOPITEMSTATUS
    freightPrice: string
    freightTemplateId: string
    id: string
    image: string
    num: number
    orderNo: string
    productId: string
    productName: string
    salePrice: string
    shopId: string
    skuId: string
    specs: string[]
    weight: number
    packageId?: string
    packageStatus: keyof typeof PACKAGESTATUS
    deliverType?: keyof typeof DeliverType
    updateTime?: string
    services: []
    isCheck: boolean
}
